home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3922 / 3922.xpi / chrome / content / overlay.js next >
Text File  |  2006-11-27  |  2KB  |  64 lines

  1. var DictionaryLookup = {
  2.  
  3.     onLoad: function() 
  4.     {
  5.         this.initialized = true;
  6.         document.getElementById("contentAreaContextMenu").addEventListener(
  7.            "popupshowing",DictionaryLookup.onContextMenu,false);
  8.     },
  9.   
  10.     onContextMenu: function()
  11.     {
  12.         var focusedWindow = document.commandDispatcher.focusedWindow;
  13.         var strSearch = focusedWindow.getSelection().toString().replace(/^\s*|\s*$/g,'');
  14.         var nLength = strSearch.length;
  15.  
  16.         if( nLength == 0 || nLength > 40 ) 
  17.             {
  18.                 // Nothing or too long text selected -> hide menu options
  19.                 document.getElementById("dictLookupSeperator").hidden = true;
  20.                 document.getElementById("dictLookupDictCtrl").hidden = true;
  21.                 document.getElementById("dictLookupWikiCtrl").hidden = true;
  22.             }
  23.         else 
  24.             {
  25.                 var bundle = document.getElementById("dictlookupLocale");
  26.  
  27.                 // enable menu options
  28.                 document.getElementById("dictLookupSeperator").hidden = false;
  29.                 document.getElementById("dictLookupDictCtrl").hidden = false;
  30.                 document.getElementById("dictLookupWikiCtrl").hidden = false;
  31.                 
  32.                 // display selected text, too
  33.                 document.getElementById("dictLookupDictCtrl").label =
  34.                 bundle.getString("translate") + ": \"" + strSearch + "\"";
  35.                 document.getElementById("dictLookupWikiCtrl").label = 
  36.                 bundle.getString("wikipediaLookup") + ": \"" + strSearch + "\"";
  37.             }
  38.     },
  39.  
  40.     dictLookup: function() 
  41.     {
  42.         // what a nice command:
  43.         var strSearch = document.commandDispatcher.focusedWindow.getSelection().toString().replace(/^\s*|\s*$/g,'');
  44.         var bundle = document.getElementById("dictlookupLocale");
  45.         var DICTIONARY_URL = bundle.getString("DICTIONARY_URL");
  46.  
  47.         var strAddr = DICTIONARY_URL + encodeURIComponent(strSearch);
  48.  
  49.         window.open( strAddr,
  50.                     'querybox',
  51.                     'status=no,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,width=300,height=400');
  52.     },
  53.   
  54.     wikiLookup: function() 
  55.     {
  56.         var strSearch = document.commandDispatcher.focusedWindow.getSelection().toString().replace(/^\s*|\s*$/g,'');
  57.         var bundle = document.getElementById("dictlookupLocale");
  58.         var LEXICON_URL = bundle.getString("LEXICON_URL");
  59.  
  60.         getBrowser().addTab(LEXICON_URL + encodeURIComponent(strSearch));
  61.     },
  62. };
  63.  
  64. window.addEventListener("load", function(e) { DictionaryLookup.onLoad(e); }, false);